//https://leetcode.com/problems/longest-substring-without-repeating-characters/

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        
        int has [ 256  ] , ans = 1 ; 
        memset ( has , 0 , sizeof ( has ) ) ; 
        
        int n = s.length() , i = 0 , start = 0 ; 
        if ( !n )
                return 0 ; 
        while ( i < n and s [ i ] == ' ' )
                i++ ; 
        
        for (  ; i < n ; i ++ )
        {
               while (  has [ s [ i ]  ]  == 1 )
               {
                   
                   has [ s [ start ]  ]  -- ;
                   start ++ ; 
               }
           
               ans = max ( ans , i - start + 1  ) ;
               has [ s [ i ]  ] = 1 ; 
           
        }
        
        
        return ans ; 
        
    }
};
